package com.first.core.service.impl;

import java.io.Serializable;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.first.core.common.QueryFilter;
import com.first.core.dao.GenericDao;
import com.first.core.service.GenericService;
import com.first.core.util.Page;
import com.first.core.util.PageUtil;
import com.first.core.util.PagingBean;

public class GenericServiceImpl<T, PK extends Serializable> implements
		GenericService<T, PK> {
	protected Log logger = LogFactory.getLog(GenericServiceImpl.class);

	protected GenericDao<T, Serializable> dao = null;

	public void setDao(GenericDao dao) {
		this.dao = dao;
	}

	public GenericServiceImpl(GenericDao dao) {
		this.dao = dao;
	}
	
	//------------------------- hibernate 相关接口

	public T get(String id) {
		return this.dao.get(id);
	}

	public T save(T entity) {
		return this.dao.save(entity);
	}

	public T merge(T entity) {
		return this.dao.merge(entity);
	}

	public void evict(T entity) {
		this.dao.evict(entity);
	}

	public List<T> getAll() {
		return this.dao.getAll();
	}

	public List<T> getAll(PagingBean pb) {
		return this.dao.getAll(pb);
	}

	public List<T> getAll(QueryFilter filter) {
		return this.dao.getAll(filter);
	}

	public void remove(String id) {
		this.dao.remove(id);
	}

	public void remove(T entity) {
		this.dao.remove(entity);
	}

	public void flush() {
		this.dao.flush();
	}

	@Override
	public void execHql(String hql, Object[] objs) {
		this.dao.executeHql(hql, objs);
	}
	
	//------------------------- hibernate 相关接口   END.
	
	
	//------------------------- ibatis 相关接口
	
	public List<T> ibGetAll() {
		return this.dao.ibGetAll();
	}

	public T ibGet(PK id) {
		return this.dao.ibGet(id);
	}

	public boolean ibExists(PK id) {
		return this.dao.ibExists(id);
	}

	public T ibSave(T object) {
		return this.dao.ibSave(object);
	}

	public void ibRemove(PK id) {
		this.dao.ibRemove(id);
	}

	@Deprecated
	public PageUtil<T> ibFindQueryPage(Object parameterObject, int currentPage,
			int pageSize) {
		return this.dao.ibFindQueryPage(parameterObject, currentPage, pageSize);
	}

	public List ibFindQueryPage(String statementList, String statementCount,
			Object parameter, Page page) {
		return this.dao.ibFindQueryPage(statementList, statementCount, parameter, page);
	}
	//------------------------- ibatis 相关接口   END.

}
